package com.study.leetcode;

import java.util.Stack;

/**
 * @author Honglixi
 * @create 2021-03-25 17:10
 */
public class leetcode20 {
    public boolean isValid(String s) {
        Stack<Character> stack = new Stack<Character>();
        for(char c:s.toCharArray()){
            if(c == '('){
                stack.push(')');
            }else if(c == '['){
                stack.push(']');
            }else if(c == '{'){
                stack.push('}');
            }else if(stack.isEmpty() || c!= stack.pop()){
                return false;
            }
        }
        return stack.isEmpty();
    }
}